/*     */ package com.qmsk.business.member.memberdepositbill.controller;
/*     */ 
/*     */ import com.qmsk.business.bussBill.bussBill.dao.BussBillDao;
/*     */ import com.qmsk.business.bussBill.pbPaid.PbPaid;
/*     */ import com.qmsk.business.info.integralCash.dao.IntegralCashDao;
/*     */ import com.qmsk.business.info.integralcoupon.dao.IntegralCouponDao;
/*     */ import com.qmsk.business.member.bussbillpaycheck.dao.BussBillPayCheckDao;
/*     */ import com.qmsk.business.member.bussbillpaypos.dao.BussBillPayPosDAO;
/*     */ import com.qmsk.business.member.member.dao.MemberDAO;
/*     */ import com.qmsk.business.member.memberAct.MemberActConst;
/*     */ import com.qmsk.business.member.memberCashCoupBill.dao.MemberCashCouponBillDao;
/*     */ import com.qmsk.business.member.memberCashCoupDetail.dao.MemberCashCouponDetailDAO;
/*     */ import com.qmsk.business.member.memberIntegralBill.dao.MemberIntegralBillDao;
/*     */ import com.qmsk.business.member.memberIntegralDetail.dao.MemberIntegralDetailDAO;
/*     */ import com.qmsk.business.member.memberLog.dao.MemberLogDAO;
/*     */ import com.qmsk.business.member.memberdepositbill.dao.MemberDepositBillDAO;
/*     */ import com.qmsk.business.member.shopMember.dao.ShopMemberDAO;
/*     */ import com.qmsk.business.shopList.ShopMap;
/*     */ import com.qmsk.business.store.salebill.params.SaleBillModel;
/*     */ import com.qmsk.business.store.storedRule.dao.StoredRuleDtlDao;
/*     */ import com.qmsk.session.UserSessionInfo;
/*     */ import com.utils.basic.CDateTimeComm;
/*     */ import com.utils.basic.MapUtils;
/*     */ import com.utils.basic.ObjectComm;
/*     */ import com.utils.gson.in.GsonHeadOneRow;
/*     */ import com.utils.gson.in.ParserDataSetJson;
/*     */ import com.utils.gson.out.GsonEbRst;
/*     */ import com.utils.http.HttpGsonPtResponseUtils;
/*     */ import com.utils.jdbc.connection.DbConnection;
/*     */ import com.utils.web.RequestUtils;
/*     */ import com.utils.web.ResponseUtils;
/*     */ import java.io.IOException;
/*     */ import java.math.BigDecimal;
/*     */ import java.sql.SQLException;
/*     */ import java.util.Date;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import org.apache.log4j.Logger;
/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.stereotype.Controller;
/*     */ import org.springframework.transaction.annotation.Transactional;
/*     */ import org.springframework.web.bind.annotation.PathVariable;
/*     */ import org.springframework.web.bind.annotation.RequestMapping;
/*     */ 
/*     */ @Controller
/*     */ @RequestMapping({"/memberDepositBill"})
/*     */ public class MemberDepositBillController
/*     */ {
/*  60 */   private static final Logger logger = Logger.getLogger(MemberDepositBillController.class);
/*     */ 
/*     */   @Autowired
/*     */   private MemberDepositBillDAO dao;
/*     */ 
/*     */   @Autowired
/*     */   private MemberDAO memberDAO;
/*     */ 
/*     */   @Autowired
/*     */   private MemberLogDAO memberLogDAO;
/*     */ 
/*     */   @Autowired
/*     */   private ShopMemberDAO shopMemberDAO;
/*     */ 
/*     */   @Autowired
/*     */   private IntegralCashDao integralCashDao;
/*     */ 
/*     */   @Autowired
/*     */   private IntegralCouponDao integralCouponDao;
/*     */ 
/*     */   @Autowired
/*     */   private MemberIntegralBillDao memberIntegralBillDao;
/*     */ 
/*     */   @Autowired
/*     */   private MemberIntegralDetailDAO integralDetailDAO;
/*     */ 
/*     */   @Autowired
/*     */   private MemberCashCouponBillDao memberCashCouponBillDao;
/*     */ 
/*     */   @Autowired
/*     */   private MemberCashCouponDetailDAO memberCashCouponDetailDAO;
/*     */ 
/*     */   @Autowired
/*     */   private StoredRuleDtlDao storedRuleDtlDao;
/*     */ 
/*     */   @Autowired
/*     */   private BussBillDao bussBillDao;
/*     */ 
/*     */   @Autowired
/*     */   private BussBillPayCheckDao bussbillpaycheckDao;
/*     */ 
/*     */   @Autowired
/*     */   private BussBillPayPosDAO bussbillPayPosDao;
/*     */ 
/*     */   @RequestMapping(value={"find/shopId/{shopId}/{pageIdx}/{pageSize}"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void getListShopId(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") Integer shopId, @PathVariable("pageIdx") Integer nPageIdx, @PathVariable("pageSize") Short nPageSize)
/*     */   {
/* 119 */     nPageSize = RequestUtils.getRequestValidPageSize(nPageSize);
/*     */     try {
/* 121 */       GsonEbRst gsonEbRst = this.dao.getGsonOfShopId(shopId, nPageIdx, 
/* 122 */         nPageSize);
/* 123 */       ResponseUtils.setResponseResult(gsonEbRst, response);
/*     */     } catch (SQLException e) {
/* 125 */       logger.error(e);
/* 126 */       ResponseUtils.setErrorMsgResponse(
/* 127 */         RequestUtils.getFindDataErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @RequestMapping(value={"find/shopId/{shopId}/{memberId}/{pageIdx}/{pageSize}"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void getListMemberId(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") String shopId, @PathVariable("memberId") Long memberId, @PathVariable("pageIdx") Integer nPageIdx, @PathVariable("pageSize") Short nPageSize)
/*     */   {
/* 147 */     nPageSize = RequestUtils.getRequestValidPageSize(nPageSize);
/*     */     try {
/* 149 */       GsonEbRst gsonEbRst = this.dao.getGsonOfMemberId(null, memberId, 
/* 150 */         nPageIdx, nPageSize);
/* 151 */       ResponseUtils.setResponseResult(gsonEbRst, response);
/*     */     } catch (SQLException e) {
/* 153 */       logger.error(e);
/* 154 */       ResponseUtils.setErrorMsgResponse(
/* 155 */         RequestUtils.getFindDataErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @RequestMapping(value={"find/shopId/{shopId}/params/{pageIdx}/{pageSize}"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void getListMemberId1(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") String shopId, @PathVariable("pageIdx") Integer nPageIdx, @PathVariable("pageSize") Short nPageSize)
/*     */   {
/* 174 */     nPageSize = RequestUtils.getRequestValidPageSize(nPageSize);
/*     */     try {
/* 176 */       Map params = new HashMap();
/* 177 */       MapUtils.addToMap(params, "msStatus", 
/* 178 */         RequestUtils.getInt(request, "msState"));
/* 179 */       MapUtils.addToMap(params, "cardNo", 
/* 180 */         RequestUtils.getString(request, "cardNo"));
/* 181 */       MapUtils.addPercentToMap(params, "custName", 
/* 182 */         RequestUtils.getString(request, "name"));
/* 183 */       MapUtils.addToMap(params, "mp", 
/* 184 */         RequestUtils.getString(request, "mp"));
/* 185 */       MapUtils.addToMap(params, "levelId", 
/* 186 */         RequestUtils.getInt(request, "level"));
/* 187 */       MapUtils.addToMap(params, "birthday", 
/* 188 */         RequestUtils.getDate(request, "birthday"));
/* 189 */       MapUtils.addToMap(params, "status", 
/* 190 */         RequestUtils.getInt(request, "status"));
/* 191 */       MapUtils.addToMap(params, "paid", 
/* 192 */         RequestUtils.getInt(request, "paid"));
/* 193 */       MapUtils.addToMap(params, "dtCreateStart", 
/* 194 */         RequestUtils.getDate(request, "dtCreateStart"));
/* 195 */       MapUtils.addToMap(params, "dtCreateEnd", 
/* 196 */         RequestUtils.getDate(request, "dtCreateEnd"));
/* 197 */       GsonEbRst gsonEbRst = this.dao.getGsonOfMemberId1(params, nPageIdx, 
/* 198 */         nPageSize);
/* 199 */       ResponseUtils.setResponseResult(gsonEbRst, response);
/*     */     } catch (SQLException e) {
/* 201 */       logger.error(e);
/* 202 */       ResponseUtils.setErrorMsgResponse(
/* 203 */         RequestUtils.getFindDataErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @RequestMapping(value={"find/shopId/{shopId}/id/{id}"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void getListOfId(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") String shopId, @PathVariable("id") Long id)
/*     */   {
/*     */     try
/*     */     {
/* 212 */       Map params = new HashMap();
/* 213 */       MapUtils.addToMap(params, "id", id);
/* 214 */       GsonEbRst gsonEbRst = this.dao.getGsonOfAll(params, Integer.valueOf(0), Short.valueOf((short) 1));
/* 215 */       ResponseUtils.setResponseResult(gsonEbRst, response);
/*     */     } catch (SQLException e) {
/* 217 */       logger.error(e);
/* 218 */       ResponseUtils.setErrorMsgResponse(
/* 219 */         RequestUtils.getFindDataErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @RequestMapping(value={"find/shopId/{shopId}/opt/{pageIdx}/{pageSize}"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void getListOptShopId(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") Long shopId, @PathVariable("pageIdx") Integer nPageIdx, @PathVariable("pageSize") Short nPageSize)
/*     */   {
/* 228 */     nPageSize = RequestUtils.getRequestValidPageSize(nPageSize);
/*     */     try {
/* 230 */       Map params = new HashMap();
/* 231 */       MapUtils.addToMap(params, "shopId", shopId);
/* 232 */       GsonEbRst gsonEbRst = this.dao.getGsonOfAll(params, nPageIdx, nPageSize);
/* 233 */       ResponseUtils.setResponseResult(gsonEbRst, response);
/*     */     } catch (Exception e) {
/* 235 */       logger.error(e);
/* 236 */       ResponseUtils.setErrorMsgResponse(
/* 237 */         RequestUtils.getFindDataErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @Transactional
/*     */   @RequestMapping(value={"paid/shopId/{shopId}"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void paid(HttpServletRequest request, HttpServletResponse response)
/*     */   {
/* 253 */     Long id = ObjectComm.stringToLong(RequestUtils.getString(request, 
/* 254 */       "id"));
/* 255 */     Long userId = UserSessionInfo.getIntUserIdOfRequest(request);
/* 256 */     String userName = UserSessionInfo.getUserNameOfRequest(request);
/* 257 */     Double deposit = Double.valueOf(0.0D);
/* 258 */     Double giveDeposit = Double.valueOf(0.0D);
/* 259 */     int nResult = 0;
/*     */     try {
/* 261 */       GsonHeadOneRow r = this.dao.getDepositOfId(id);
/* 262 */       deposit = ObjectComm.objectToDouble(r.getValueOfName("Amount"), Integer.valueOf(0));
/* 263 */       ParserDataSetJson pay = ParserDataSetJson.fromString(
/* 264 */         RequestUtils.getString(request, "pay"));
/* 265 */       GsonHeadOneRow g = (GsonHeadOneRow)pay.getListInsertRows().get(0);
/* 266 */       if ((r != null) && (deposit.doubleValue() > 0.0D) && (g != null)) {
/* 267 */         ParserDataSetJson payPos = 
/* 268 */           ParserDataSetJson.fromString(RequestUtils.getString(request, "payPos"));
/* 269 */         ParserDataSetJson pCheck = 
/* 270 */           ParserDataSetJson.fromString(RequestUtils.getString(request, "payBnk"));
/* 271 */         nResult = paidDeposit(r, g, id, userId, userName, deposit, 
/* 272 */           payPos, pCheck, giveDeposit, request, response);
/*     */       } else {
/* 274 */         ResponseUtils.setErrorMsgResponse("没有符合条件的数据", response);
/* 275 */         return;
/*     */       }
/* 277 */       if (nResult > 0) {
/* 278 */         DbConnection.commit();
/* 279 */         String[] head = { "GotDeposit" };
/* 280 */         Object[] data = { giveDeposit };
/* 281 */         ResponseUtils.toGsonEbRst(head, data, response);
/* 282 */         return; }
/* 283 */       DbConnection.rollback();
/* 284 */       PbPaid.getResponse(nResult, response);
/*     */     }
/*     */     catch (Exception e) {
/* 287 */       DbConnection.rollback();
/* 288 */       logger.error(e);
/* 289 */       ResponseUtils.setErrorMsgResponse(
/* 290 */         RequestUtils.getSqlUpdateDataErrorMessage(request) + ":" + 
/* 291 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @Transactional
/*     */   @RequestMapping(value={"insert/shopId/{shopId}"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void insert(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") Long shopId)
/*     */     throws IOException
/*     */   {
/*     */     try
/*     */     {
/* 311 */       int nResult = 0;
/* 312 */       String sMaxBillNo = null;
/* 313 */       Long id = null;
/* 314 */       Date dCreate = null;
/* 315 */       String sData = RequestUtils.getStringOfData(request);
/* 316 */       ParserDataSetJson p = ParserDataSetJson.fromString(sData);
/* 317 */       if (p != null) {
/* 318 */         if (p.isExistsInsertRows()) {
/* 319 */           for (int i = 0; i < p.getListInsertRows().size(); ++i) {
/* 320 */             GsonHeadOneRow r = (GsonHeadOneRow)p.getListInsertRows().get(i);
/* 321 */             String userName = 
/* 322 */               UserSessionInfo.getUserNameOfRequest(request);
/* 323 */             sMaxBillNo = this.dao.getMaxBillNo(shopId);
/* 324 */             r.autoAddHeadData("BillNo", sMaxBillNo);
/* 325 */             r.autoAddHeadData("CreateFileMan", userName);
/* 326 */             dCreate = new Date();
/* 327 */             r.autoAddHeadData("CreateFileTime", dCreate);
/* 328 */             r.autoAddHeadData("ShopId", shopId);
/*     */           }
/*     */         }
/* 331 */         nResult = this.dao.applyUpdates(p);
/*     */       }
/*     */ 
/* 334 */       if (nResult > 0) {
/* 335 */         id = this.dao.getLastId();
/* 336 */         DbConnection.commit();
/* 337 */         String[] head = { "id", "BillNo", "dtCreate" };
/* 338 */         Object[] data = { id, sMaxBillNo, dCreate };
/* 339 */         ResponseUtils.toGsonEbRst(head, data, response);
/* 340 */         return; }
/* 341 */       DbConnection.rollback();
/* 342 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 343 */         RequestUtils.getSqlInsertDataErrorMessage(request), 
/* 344 */         response);
/*     */     }
/*     */     catch (Exception e) {
/* 347 */       DbConnection.rollback();
/* 348 */       logger.error(e);
/* 349 */       ResponseUtils.setErrorMsgResponse(
/* 350 */         RequestUtils.getSqlInsertDataErrorMessage(request) + ":" + 
/* 351 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   private int paidDeposit(GsonHeadOneRow r, GsonHeadOneRow g, Long id, Long userId, String userName, Double dDeposit, ParserDataSetJson payPos, ParserDataSetJson pCheck, Double giveDeposit, HttpServletRequest request, HttpServletResponse response)
/*     */     throws Exception
/*     */   {
/* 360 */     int nResult = 0;
/* 361 */     String memo = null;
/* 362 */     if (r != null) {
/* 363 */       Long shopId = ObjectComm.objectToLong(r.getValueOfName("shopId"));
/* 364 */       Long memberId = ObjectComm.objectToLong(r
/* 365 */         .getValueOfName("memberId"));
/* 366 */       String billNo = (String)r.getValueOfName("billNo");
/* 367 */       String memo1 = (String)r.getValueOfName("Memo");
/* 368 */       Long storRuledtlID = ObjectComm.objectToLong(r
/* 369 */         .getValueOfName("storRuledtlID"));
/* 370 */       if (memo1 != null) {
/* 371 */         memo = memo1;
/*     */       }
/* 373 */       Double nCash = Double.valueOf(0.0D);
/* 374 */       Long outSId = ShopMap.getOutIdOfShopId(shopId);
/* 375 */       Long outMId = this.memberDAO.getOutMIdOfId(memberId);
/*     */ 
/* 377 */       if (dDeposit.doubleValue() > 0.0D) {
/* 378 */         SaleBillModel saleBillModel = new SaleBillModel();
/*     */ 
/* 381 */         nResult = nResult + 
/* 381 */           getGivePresent(dDeposit, memberId, shopId, memo, 
/* 380 */           storRuledtlID, billNo, userId, userName, 
/* 381 */           Integer.valueOf(25), saleBillModel);
/* 382 */         Double nDeposit = ObjectComm.objectToDouble(
/* 383 */           saleBillModel.getGiveAmt(), Double.valueOf(0.0D));
/* 384 */         nResult += this.memberDAO.updateMemberInc(memberId, dDeposit);
/*     */ 
/* 386 */         nResult = nResult + this.shopMemberDAO
/* 386 */           .updateMemberInc(memberId, dDeposit, 
/* 386 */           shopId);
/* 387 */         if (nDeposit.doubleValue() > 0.0D) {
/* 388 */           giveDeposit = nDeposit;
/* 389 */           dDeposit = Double.valueOf(dDeposit.doubleValue() + nDeposit.doubleValue());
/* 390 */           nResult += this.dao.updateGotDepositOfid(nDeposit, id);
/*     */         }
/* 392 */         nResult += this.memberDAO.updateMbBusBIllDeposit(memberId, dDeposit);
/*     */ 
/* 394 */         nResult = nResult + this.shopMemberDAO
/* 394 */           .updateMbBusBIllDeposit(memberId, 
/* 394 */           dDeposit, shopId);
/* 395 */         if (nResult > 0)
/* 396 */           if ((outSId != null) && (outMId.longValue() > 0L)) {
/* 397 */             GsonHeadOneRow pa = this.shopMemberDAO
/* 398 */               .getPaidOneRowOfMemberId(memberId, shopId);
/* 399 */             if ((pa != null) && (pa.getDataLength() > 0)) {
/* 400 */               Double discount = saleBillModel.getDiscount();
/* 401 */               if ((discount != null) && (discount.doubleValue() > 0.0D)) {
/* 402 */                 pa.autoAddHeadData("discount", discount);
/* 403 */                 String[] heads = { "Discount", 
/* 404 */                   "ShopID", "MemberID" };
/* 405 */                 Object[] datas = { discount, 
/* 406 */                   shopId, id };
/* 407 */                 GsonHeadOneRow gs = new GsonHeadOneRow(heads, 
/* 408 */                   datas);
/* 409 */                 this.shopMemberDAO.updateJsonHeadOneRow(gs, 
/* 410 */                   "crm_shop_member");
/* 411 */                 gs.delHead("ShopID");
/* 412 */                 gs.delHead("MemberID");
/* 413 */                 this.memberDAO.updateJsonOneRow(gs, memberId);
/*     */               }
/* 415 */               pa.autoAddHeadData("shopId", outSId);
/* 416 */               String nData = "data=" + 
/* 417 */                 pa.objectToJsonStr() + "&" + 
/* 418 */                 "id" + "=" + outMId;
/* 419 */               String sUrl = "ptmember/editPaid";
/* 420 */               GsonEbRst rst = 
/* 421 */                 HttpGsonPtResponseUtils.postPtEbRst(sUrl, nData, response);
/* 422 */               if ((rst == null) || (rst.getState() != 0))
/* 423 */                 return -14;
/*     */             }
/*     */             else {
/* 426 */               return -14;
/*     */             }
/*     */           }
/*     */         else {
/* 430 */           return nResult;
/*     */         }
/*     */ 
/* 460 */         if (nResult > 0) {
/* 461 */           int rst = 0;
/* 462 */           String[] heads = { "ShopID", "MemberID", 
/* 463 */             "CustId", "CustName", "BillNo", "ReceId", 
/* 464 */             "ReceName", "ReceDate", "CreateTime", "BillAmt", 
/* 465 */             "FactAmt", "PayCash", "PayPos", "PayCheck", 
/* 466 */             "STATUS", "BillPaid", "stId", "GotIntAmt", 
/* 467 */             "GotCashCoup", "GotDeposit" };
/* 468 */           Double cash = ObjectComm.objectToDouble(
/* 469 */             g.getValueOfName("cashAmt"), Double.valueOf(0.0D));
/* 470 */           Double pos = ObjectComm.objectToDouble(
/* 471 */             g.getValueOfName("bnkAmt"), Double.valueOf(0.0D));
/* 472 */           Double check = ObjectComm.objectToDouble(
/* 473 */             g.getValueOfName("chkAmt"), Double.valueOf(0.0D));
/* 474 */           Double factAmt = 
/* 478 */             Double.valueOf(new BigDecimal(String.valueOf(cash
/* 475 */             .doubleValue() + 
/* 476 */             pos.doubleValue() + 
/* 477 */             check.doubleValue())).setScale(0, 
/* 478 */             4).doubleValue());
/* 479 */           Object[] datas = { 
/* 480 */             shopId, 
/* 481 */             memberId, 
/* 482 */             r.getValueOfName("custId"), 
/* 483 */             r.getValueOfName("custName"), 
/* 484 */             billNo, 
/* 485 */             userId, 
/* 486 */             userName, 
/* 487 */             CDateTimeComm.dateToyyyymmdd(new Date()), 
/* 488 */             new Date(), 
/* 489 */             dDeposit, 
/* 490 */             factAmt, 
/* 491 */             cash, 
/* 492 */             pos, 
/* 493 */             check, 
/* 494 */             Integer.valueOf(0), 
/* 495 */             Integer.valueOf(1), 
/* 496 */             Integer.valueOf(25), 
/* 497 */             ObjectComm.objectToInteger(
/* 498 */             saleBillModel.getGiveIntgral(), Integer.valueOf(0)), 
/* 499 */             ObjectComm.objectToDouble(
/* 500 */             saleBillModel.getCashCoup(), Double.valueOf(0.0D)), 
/* 501 */             nDeposit };
/* 502 */           GsonHeadOneRow buss = new GsonHeadOneRow(heads, datas);
/* 503 */           rst = this.bussBillDao
/* 504 */             .insertGsonHeadOneRow(buss, "crm_bussbill");
/* 505 */           if (rst > 0) {
/* 506 */             Long bussId = this.bussBillDao.getLastId();
/*     */             int i;
/*     */             GsonHeadOneRow s;
/* 507 */             if (pCheck != null) {
/* 508 */               if (pCheck.isExistsInsertRows()) {
/* 509 */                 for (i = 0; i < pCheck.getListInsertRows()
/* 510 */                   .size(); )
/*     */                 {
/* 511 */                   s = 
/* 512 */                     (GsonHeadOneRow)pCheck
/* 512 */                     .getListInsertRows().get(i);
/* 513 */                   if (id != null)
/* 514 */                     s.autoAddHeadData("id", bussId);
/* 510 */                   ++i;
/*     */                 }
/*     */ 
/*     */               }
/*     */ 
/* 519 */               rst = rst + this.bussbillpaycheckDao
/* 519 */                 .applyUpdates(pCheck);
/*     */             }
/*     */ 
/* 522 */             if (payPos != null) {
/* 523 */               if (payPos.isExistsInsertRows()) {
/* 524 */                 for (i = 0; i < payPos.getListInsertRows()
/* 525 */                   .size(); )
/*     */                 {
/* 526 */                   s = 
/* 527 */                     (GsonHeadOneRow)payPos
/* 527 */                     .getListInsertRows().get(i);
/* 528 */                   if (id != null)
/* 529 */                     s.autoAddHeadData("id", bussId);
/* 525 */                   ++i;
/*     */                 }
/*     */ 
/*     */               }
/*     */ 
/* 533 */               rst += this.bussbillPayPosDao.applyUpdates(payPos);
/*     */             }
/* 535 */             if (rst > 0) {
/* 536 */               ++nResult;
/* 537 */              }
/* 538 */             return -91;
/*     */           }
/*     */ 
/* 541 */           return -90;         }
/*     */       }
/* 551 */       this.memberLogDAO.insertMemberLogBuss(MemberActConst.PAID, billNo, Double.valueOf(0.0D), 
/* 552 */         dDeposit, nCash, nCash, memberId, userId, userName);
/*     */     }
/* 554 */     return nResult;
/*     */   }
/*     */ 
/*     */   private Integer getIntegralRatioRslt(Double integralRate, Double dCach)
/*     */   {
/* 559 */     Integer intAmt = Integer.valueOf(0);
/* 560 */     Double rst = Double.valueOf(dCach.doubleValue() * integralRate.doubleValue());
/* 561 */     if (rst.doubleValue() != 0.0D) {
/* 562 */       intAmt = 
/* 563 */         Integer.valueOf(new BigDecimal(String.valueOf(rst)).setScale(0, 
/* 563 */         4).intValue());
/* 564 */       return intAmt;
/*     */     }
/* 566 */     return Integer.valueOf(0);
/*     */   }
/*     */ 
/*     */   private int insertSaleBillPaidSavingsNOAW(GsonHeadOneRow r, Double dCach, boolean dpan, String memo, String billNo, Long userId, String userName, SaleBillModel saleBillModel)
/*     */     throws SQLException
/*     */   {
/* 583 */     int nRstl = 0;
/* 584 */     Integer intAmt = Integer.valueOf(0);
/* 585 */     Double payCahCouPon = Double.valueOf(0.0D);
/* 586 */     Long shopId = (Long)r.getValueOfName("shopId");
/* 587 */     Long memberId = (Long)r.getValueOfName("memberId");
/* 588 */     Integer fixedIntegral = (Integer)r.getValueOfName("FixedIntegral");
/* 589 */     String conSumeType = (String)r.getValueOfName("ConsumeType");
/* 590 */     if (conSumeType.equals("固定积分")) {
/* 591 */       if (dpan)
/* 592 */         intAmt = fixedIntegral;
/*     */       else
/* 594 */         payCahCouPon = Double.valueOf(fixedIntegral.doubleValue());
/*     */     }
/*     */     else {
/* 597 */       Double integralRate = ObjectComm.objectToDouble(
/* 598 */         r.getValueOfName("IntegralRate"), Integer.valueOf(0));
/* 599 */       if (dpan)
/* 600 */         intAmt = getIntegralRatioRslt(integralRate, dCach);
/*     */       else
/* 602 */         payCahCouPon = 
/* 603 */           Double.valueOf(getIntegralRatioRslt(integralRate, dCach)
/* 603 */           .doubleValue());
/*     */     }
/*     */     Long RuleID;
/*     */     String slName;
/*     */     String inFrom;
/*     */     Integer mberVday;
/*     */     Long billId;
/* 606 */     if ((intAmt != null) && (intAmt.intValue() > 0)) {
/* 607 */       saleBillModel.setGiveIntgral(intAmt);
/* 608 */       RuleID = (Long)r.getValueOfName("RuleID");
/* 609 */       slName = (String)r.getValueOfName("SaleName");
/* 610 */       inFrom = (String)r.getValueOfName("RuleName");
/* 611 */       mberVday = this.memberDAO.getVdayOfmemberId(memberId);
/* 612 */       nRstl = this.memberIntegralBillDao.insertBsBillInAmt(billNo, memberId, 
/* 613 */         shopId, intAmt, RuleID, inFrom, mberVday, slName, null, 
/* 614 */         memo);
/* 615 */       billId = this.memberIntegralBillDao.getLastId();
/* 616 */       nRstl = this.integralDetailDAO.insertBusBillDtialInAmt(memberId, shopId, 
/* 617 */         intAmt, mberVday, billId);
/* 618 */       if (nRstl > 0) {
/* 619 */         nRstl = this.memberDAO.updateBillMemberIntAmt(memberId, intAmt);
/* 620 */         nRstl = this.shopMemberDAO.updateBillMemberIntAmt(memberId, intAmt, 
/* 621 */           shopId);
/*     */ 
/* 623 */         this.memberLogDAO.insertBusBillMbLog_IntAmt(MemberActConst.PAID, 
/* 624 */           billNo, intAmt, memberId, userId, userName);
/*     */       } else {
/* 626 */         return -8;
/*     */       }
/*     */     }
/*     */ 
/* 630 */     if ((payCahCouPon != null) && (payCahCouPon.doubleValue() > 0.0D)) {
/* 631 */       saleBillModel.setGiveCashConp(payCahCouPon);
/* 632 */       RuleID = (Long)r.getValueOfName("RuleID");
/* 633 */       slName = (String)r.getValueOfName("SaleName");
/* 634 */       inFrom = (String)r.getValueOfName("RuleName");
/* 635 */       mberVday = this.memberDAO.getVdayOfmemberId(memberId);
/* 636 */       nRstl = this.memberCashCouponBillDao.insertCashCoupoBill(billNo, 
/* 637 */         memberId, shopId, payCahCouPon, RuleID, inFrom, mberVday, 
/* 638 */         slName, null, memo);
/* 639 */       billId = this.memberCashCouponBillDao.getLastId();
/* 640 */       nRstl = this.memberCashCouponDetailDAO.insertCashCoupDtialCash(memberId, 
/* 641 */         shopId, payCahCouPon, mberVday, inFrom, billId);
/* 642 */       if (nRstl > 0) {
/* 643 */         nRstl = this.memberDAO
/* 644 */           .updateBissBillCashConp(memberId, payCahCouPon);
/* 645 */         nRstl = this.shopMemberDAO.updateBissBillCashConp(memberId, 
/* 646 */           payCahCouPon, shopId);
/*     */ 
/* 649 */         this.memberLogDAO.insertBusBillMbLog_CashCoup(MemberActConst.PAID, 
/* 650 */           billNo, payCahCouPon, memberId, userId, userName);
/*     */       } else {
/* 652 */         return -7;
/*     */       }
/*     */     }
/* 655 */     return nRstl;
/*     */   }
/*     */ 
/*     */   private int getGivePresent(Double dDeposit, Long memberId, Long shopId, String memo, Long storRuledtlID, String billNo, Long userId, String userName, Integer stId, SaleBillModel saleBillModel)
/*     */     throws SQLException
/*     */   {
/* 662 */     int nResult = 0;
/* 663 */     GsonHeadOneRow gg = this.integralCashDao.getBillIntegralOfId(memberId, stId, 
/* 664 */       shopId);
/* 665 */     if (gg != null) {
/* 666 */       nResult = insertSaleBillPaidSavingsNOAW(gg, dDeposit, true, memo, 
/* 667 */         billNo, userId, userName, saleBillModel);
/* 668 */       if (nResult < 0) {
/* 669 */         return nResult;
/*     */       }
/*     */     }
/*     */ 
/* 673 */     GsonHeadOneRow qq = this.integralCouponDao.getBillCashCouPonOfId(memberId, 
/* 674 */       stId, shopId);
/* 675 */     if (qq != null)
/*     */     {
/* 677 */       nResult = nResult + 
/* 677 */         insertSaleBillPaidSavingsNOAW(qq, dDeposit, false, memo, 
/* 677 */         billNo, userId, userName, saleBillModel);
/* 678 */       if (nResult < 0) {
/* 679 */         return nResult;
/*     */       }
/*     */     }
/*     */ 
/* 683 */     if ((storRuledtlID != null) && (storRuledtlID.longValue() > 0L)) {
/* 684 */       GsonHeadOneRow dp = this.storedRuleDtlDao
/* 685 */         .getStoredRuleofId(storRuledtlID);
/* 686 */       if (dp != null) {
/* 687 */         Double giveAmt = ObjectComm.objectToDouble(
/* 688 */           dp.getValueOfName("giveAmt"), Integer.valueOf(0));
/* 689 */         Double storedAmt = ObjectComm.objectToDouble(
/* 690 */           dp.getValueOfName("storedAmt"), Integer.valueOf(0));
/* 691 */         Double discount = ObjectComm.objectToDouble(
/* 692 */           dp.getValueOfName("discount"), Integer.valueOf(0));
/* 693 */         if ((discount != null) && (discount.doubleValue() > 0.0D)) {
/* 694 */           saleBillModel.setDiscount(discount);
/*     */         }
/* 696 */         if ((giveAmt.doubleValue() > 0.0D) && (dDeposit.doubleValue() >= storedAmt.doubleValue()))
/*     */         {
/* 702 */           saleBillModel.setGiveAmt(giveAmt);
/*     */         }
/*     */       }
/*     */     }
/* 706 */     return nResult;
/*     */   }
/*     */ 
/*     */   @Transactional
/*     */   @RequestMapping(value={"del/shopId/{shopId}"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void delete(HttpServletRequest request, HttpServletResponse response)
/*     */   {
/* 722 */     String id = RequestUtils.getStringOfId(request);
/*     */     try {
/* 724 */       String[] strParams = id.split(",");
/* 725 */       int nResult = this.dao.deleteParams(strParams);
/* 726 */       Long bussId = this.dao.getBussBillOfBussId(id);
/* 727 */       if (bussId.longValue() > 0L) {
/* 728 */         String[] bussParams = { String.valueOf(bussId) };
/* 729 */         nResult += this.bussBillDao.deleteParams(bussParams);
/* 730 */         nResult += this.bussbillpaycheckDao.deleteOfbussIds(bussParams);
/* 731 */         nResult += this.bussbillPayPosDao.deleteOfbussIds(bussParams);
/*     */       }
/* 733 */       if (nResult > 0)
/* 734 */         DbConnection.commit();
/*     */       else {
/* 736 */         DbConnection.rollback();
/*     */       }
/* 738 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 739 */         RequestUtils.getSqlDeleteDataErrorMessage(request), 
/* 740 */         response);
/*     */     } catch (Exception e) {
/* 742 */       DbConnection.rollback();
/* 743 */       logger.error(e);
/* 744 */       ResponseUtils.setErrorMsgResponse(
/* 745 */         RequestUtils.getSqlDeleteDataErrorMessage(request) + ":" + 
/* 746 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @Transactional
/*     */   @RequestMapping(value={"edit/shopId/{shopId}"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void update(HttpServletRequest request, HttpServletResponse response)
/*     */   {
/*     */     try
/*     */     {
/* 763 */       int nResult = 0;
/* 764 */       String sData = RequestUtils.getStringOfData(request);
/* 765 */       ParserDataSetJson p = ParserDataSetJson.fromString(sData);
/* 766 */       if (p != null) {
/* 767 */         nResult = this.dao.applyUpdates(p);
/*     */       }
/* 769 */       if (nResult > 0)
/* 770 */         DbConnection.commit();
/*     */       else {
/* 772 */         DbConnection.rollback();
/*     */       }
/* 774 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 775 */         RequestUtils.getSqlUpdateDataErrorMessage(request), 
/* 776 */         response);
/*     */     } catch (Exception e) {
/* 778 */       logger.error(e);
/* 779 */       DbConnection.rollback();
/* 780 */       ResponseUtils.setErrorMsgResponse(
/* 781 */         RequestUtils.getSqlUpdateDataErrorMessage(request) + ":" + 
/* 782 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @Transactional
/*     */   @RequestMapping(value={"check/shopId/{shopId}"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void check(HttpServletRequest request, HttpServletResponse response)
/*     */   {
/* 798 */     Long id = ObjectComm.stringToLong(RequestUtils.getString(request, 
/* 799 */       "id"));
/* 800 */     Long userId = UserSessionInfo.getIntUserIdOfRequest(request);
/* 801 */     String userName = UserSessionInfo.getUserNameOfRequest(request);
/*     */     try {
/* 803 */       if (id == null) {
/* 804 */         ResponseUtils.setErrorMsgResponse("id不能为空", response);
/* 805 */         return;
/*     */       }
/* 807 */       int nResult = this.dao.updateDeposiBill(id);
/* 808 */       Long bussId = this.dao.getBussBillOfBussId(id);
/* 809 */       int result = 0;
/* 810 */       if (bussId.longValue() > 0L) {
/* 811 */         result = this.bussBillDao.updateCheckedOfIds(userId, userName, 
/* 812 */           bussId);
/*     */       }
/* 814 */       if ((nResult > 0) && (result > 0))
/* 815 */         DbConnection.commit();
/*     */       else {
/* 817 */         DbConnection.rollback();
/*     */       }
/* 819 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 820 */         RequestUtils.getSqlDeleteDataErrorMessage(request), 
/* 821 */         response);
/*     */     }
/*     */     catch (Exception e) {
/* 824 */       DbConnection.rollback();
/* 825 */       logger.error(e);
/* 826 */       ResponseUtils.setErrorMsgResponse(
/* 827 */         RequestUtils.getSqlDeleteDataErrorMessage(request) + ":" + 
/* 828 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ }

/* Location:           C:\Users\Administrator\Desktop\新建文件夹\WEB-INF\classes\
 * Qualified Name:     com.qmsk.business.member.memberdepositbill.controller.MemberDepositBillController
 * JD-Core Version:    0.5.3
 */